package com.dcivision.framework.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;

public class MaintEventCodeAction extends AbstractMaintAction {
  
  public static final String REVISION = "$Revision: 1.3 $";
  
  public MaintEventCodeAction(){
    super();
  }

  public String getFunctionCode() {
    return (SystemFunctionConstant.LOG_EVENT_MESSAGE);
  }

  public String getMajorDAOClassName() {
    return "com.dcivision.framework.dao.EventMessageCodeDAObject";
  }
  
  public void insertRecord(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    MaintEventCodeForm eventCodeForm = (MaintEventCodeForm)form;
    String msgCode = eventCodeForm.getMsgCode();
    String message = eventCodeForm.getMessageCode();
    if (Utility.isEmpty(msgCode) || "".equals(msgCode.trim())){
      throw new ApplicationException("errors.eventlog.empty_label_key");
    }
    if (Utility.isEmpty(message) || "".equals(message.trim())){
      throw new ApplicationException("errors.eventlog.empty_event_code");
    }
    TextUtility.stringValidation(msgCode);
    TextUtility.stringValidation(message);    
    super.insertRecord(mapping,eventCodeForm,request,response);
  }
  
  public void updateRecord(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    MaintEventCodeForm eventCodeForm = (MaintEventCodeForm)form;
    String msgCode = eventCodeForm.getMsgCode();
    String message = eventCodeForm.getMessageCode();
    if (Utility.isEmpty(msgCode) || "".equals(msgCode.trim())){
      throw new ApplicationException("errors.eventlog.empty_label_key");
    }
    if (Utility.isEmpty(message) || "".equals(message.trim())){
      throw new ApplicationException("errors.eventlog.empty_event_code");
    }
    TextUtility.stringValidation(msgCode);
    TextUtility.stringValidation(message);    
    super.updateRecord(mapping,eventCodeForm,request,response);
  }
}
